package com.dailyblue.project.smbms.alibaba.provider.controller;

import com.dailyblue.project.smbms.alibaba.commons.bean.Provider;
import com.dailyblue.project.smbms.alibaba.commons.util.JsonResult;
import com.dailyblue.project.smbms.alibaba.provider.service.ProviderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/provider")
@Slf4j
public class ProviderController {
    @Resource
    private ProviderService service;

    @GetMapping("/{page}")
    public JsonResult find(@PathVariable Integer page) {
        return service.find(page);
    }

    @DeleteMapping("/{id}/{page}/{count}")
    public JsonResult delete(@PathVariable int id, @PathVariable int page, @PathVariable int count) {
        return service.deleteProvider(id, page, count);
    }

    @GetMapping("/id/{id}")
    public JsonResult findById(@PathVariable int id) {
        log.info("获取{}的数据",id);
        return service.findProviderById(id);
    }

    @PostMapping
    public JsonResult save(Provider provider) {
        return service.saveProvider(provider);
    }

    @PutMapping
    public JsonResult update(Provider provider, int page) {
        return service.updateProvider(provider, page);
    }
}
